package cn.support.neo.mvp.core.base;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;


/**
 * <b>Name:</b>xx页面<br>
 * <b>Author:</b> WK（wangkun@xjzhicheng.com)<br>
 * <b>Date:</b>  2017-05-09<br>
 * <b>Describe:</b><p> PLEASE TO FIXME...</p><br>
 * <p>代码说明：（重点）<br>
 * <ol>
 * <li> write something content..</li>
 * </ol>
 * </p>
 * <b>Version:</b>V1.0<br>
 * <b>Revision History:</b>
 * <ul>
 * v1.x<li>1.write something content..。<br>2.write something content..<br>3.write something content..<br></li>
 * </ul>
 * <br>
 */
public abstract class BaseFragment extends Fragment {

    protected boolean isVisible;

    protected abstract
    @LayoutRes
    int getLayoutResID();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(getLayoutResID(), container);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this, view);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    protected void onVisible() {
        Logger.i(getClass().getSimpleName(), "On Visible..");
        lazyLoadingTask();
    }

    protected void onInvisible() {
    }

    protected abstract void initView();
    protected abstract void setListener();
    protected abstract void lazyLoadingTask();
}
